/********************************************************************************
 *      Copyright:  (C) 2025 Huang Xiangming<huangxiangming@163.com>
 *                  All rights reserved.
 *
 *       Filename:  server_function.h
 *    Description:  This file is the head file about socket server function
 *
 *        Version:  1.0.0(25/03/25)
 *         Author:  HuangXiangming <huangxiangming@163.com>
 *      ChangeLog:  1, Release initial version on "25/03/25 12:34:14"
 *                 
 ********************************************************************************/
//包含保护
#ifndef SERVERFUN_H
#define SERVERFUN_H

#include <stdint.h>

#define CRC16_ITU_T_POLY 0x1021

typedef struct data_s
{
	char	id[10];
	char	sample_time[32];
	char	temp[10];
}data_t;

//客户端初始化
int socket_server_init(char *listen_ip, int listen_port);

//客户端最大限制
void set_socket_rlimit(void);

//数据解析
int parse_data(uint8_t *buf, data_t *data);

int parse_data_json(uint8_t *buf, data_t *data);

typedef int (* parse_proc_t)(uint8_t *buf, data_t *data);

int parse_data_tlv(uint8_t *buf, data_t *data);

static uint16_t crc_itu_t(const uint8_t *data, size_t length);
#endif
